package com.kajespero.webapp.listener;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.kajespero.service.user.UserService;
import com.kajespero.service.user.impl.UserServiceImpl;
import com.kajespero.vo.UserVO;
import com.kajespero.webapp.AttributesConstants;

public class GoogleAppServletListener implements HttpSessionListener{
	
	private static final List<UserVO> USERS = new ArrayList<UserVO>();
	
	private static final UserService USER_SERVICE = new UserServiceImpl();
	
	@Override
	public void sessionCreated(HttpSessionEvent se) {
		USERS.clear();
		USERS.addAll((Collection<? extends UserVO>) USER_SERVICE.findAll());
		se.getSession().getServletContext().setAttribute(AttributesConstants.USERS_ATTRIBUTES, USERS);
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent se) {
	}
}
